﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Drawing;

namespace Mao.Core
{
	public class DataLoader
	{
		public List<Card> LoadCards(string Path)
		{
			List<Card> tmpCards = new List<Card>();

			XmlDocument doc = new XmlDocument();
			doc.Load(Path);

			XmlNodeList nodes = doc.GetElementsByTagName("Card");

			foreach (XmlNode node in nodes)
			{
				Card card = new Card();

				foreach (XmlNode innerNode in node.ChildNodes)
				{
					if (innerNode.Name == "Name")
						card.name = innerNode.InnerText;
					else if (innerNode.Name == "Image")
						card.image = Image.FromFile(innerNode.InnerText);
					else if (innerNode.Name == "Attributes")
					{
						foreach (XmlNode attr in innerNode.ChildNodes)
						{
							card.Attributes.Add(attr.Name, attr.InnerText);
						}
					}
				}

				tmpCards.Add(card);
			}

			return tmpCards;
		}
	}
}
